package com.polaris.live.ui.live.widget.adapter

import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.polaris.live.adapter.live.LiveMessageAdapter
import com.polaris.live.databinding.LiveMessageInviteFollowItemBinding
import com.polaris.live.im.sfs.bean.live.SendLiveMessage
import com.polaris.live.im.sfs.bean.live.ext.MessageUserExtBean
import com.polaris.live.im.sfs.bean.live.payload.InviteFollowPayloadBean
import com.polaris.live.ui.message.widget.single_message.AbstractLiveMessageItemHolder
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * LiveMessageInviteFollowerItem
 *
 * @author Created by 半仙 on 2023/10/24/024 9:26
 */
class LiveMessageInviteFollowerItem(
    adapter: LiveMessageAdapter,
    binding: LiveMessageInviteFollowItemBinding
) : AbstractLiveMessageItemHolder<LiveMessageInviteFollowItemBinding>(adapter, binding) {

    override fun bind(item: SendLiveMessage) {
        mBinding.apply {
            val ext = item.ext as? MessageUserExtBean?
            val payload = item.payload as? InviteFollowPayloadBean?
            if (ext != null && payload != null) {
                callFollowerText.text = item.content

                callFollowerUserHead.setImageUrl(ext.user.avatar, ext.user.userId)
                avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(ext.user.avatarFrame))

                Glide.with(callFollowerAdIm.context)
                    .load(ImageUtils.imgPath(payload.pic))
                    .transform(CircleCrop())
                    .into(callFollowerAdIm)
            } else {
                callFollowerText.text = ""
                avFv.setFrameImage(null)

                callFollowerUserHead.setImageUrl(null)
                callFollowerAdIm.setImageResource(0)
            }
        }
    }
}